#include "q_data.h"
#include "q_modify.h"
#include "ui_q_modify.h"
#include <QSqlQuery>
#include <QDebug>
#include <QMessageBox>

Q_modify::Q_modify(QWidget* parent) :
    QWidget(parent),
    ui(new Ui::Q_modify)
{
    ui->setupUi(this);
}

Q_modify::~Q_modify()
{
    delete ui;
}

void Q_modify::on_pushButtonBack_clicked()
{
    Q_data* m = new Q_data();
    m->show();
    this->close();
}


void Q_modify::on_pushButtonOk_clicked()
{
    QString Newname = ui ->Newname ->text();
    QString Newage = ui ->Newage->text();
    QString Newbanji = ui ->Newbanji ->text();
    QString Newhoppy = ui ->Newhoppy->text();

    QSqlQuery query;

    query.prepare("UPDATE wenjuan SET name=?, age=?, banji=?, hoppy=? WHERE name=?");
    query.addBindValue(Newname);
    query.addBindValue(Newage);
    query.addBindValue(Newbanji);
    query.addBindValue(Newhoppy);
    query.addBindValue(Newname);
    if(query.exec())
    {
        qDebug() << "连接成功";
        QMessageBox::warning(this, "成功！", "修改成功！！！");
    }
    else
    {
        qDebug() << "连接失败！！";
    }
    ui->Newname->clear();
    ui->Newage->clear();
    ui->Newbanji->clear();
    ui->Newhoppy->clear();

}
